<template>	
	<view class="wanlshop-container" style="padding-top: 135rpx;">	
		<view
			v-if="common.modulesData.homeModules.page"
			class="wanlshop-container__head"
		>
			<view style="height: 138rpx;paddingTop: 40rpx">
				<view class="navigater flex align-center justify-between">		
					<view style="position: fixed;top: 30px;">
						<image class="image_logo" src="/static/images/home/logo.png"></image>
					</view>
				</view>
			</view>
		</view>
		<!-- 主体 -->
		
		<wanl-shop-page
			:windowHeight="windowHeight"
			:headHeight="headHeight"
			:headTop="headTop"
			:pageModules="common.modulesData.homeModules"
			:adData="common.adData"
		/>
		<view style="height: 100rpx;"></view>
		
	<!-- 	<tab-bar></tab-bar> -->
		<nxc-show v-if="(show && user.isLogin && user.isbuy == 0) || (show && !user.isLogin)" :content="showmsg"></nxc-show>
		<!-- 弹窗 -->
		<view class="WANL-MODAL" @touchmove.stop.prevent="moveHandle">
			<!-- 顶部 -->
			<view class="cu-modal top-modal" :class="{ show: isModal }" @tap="handleModal">
				<view
					class="cu-dialog padding-lr-bj padding-bottom-bj"
					:style="{ paddingTop: headHeight + 12 + 'px' }"
					@tap.stop=""
				>
					<view class="category text-min">
						<view
							class="item round bg-gray"
							:class="{ action: currentItemId === 'follow' }"
							@tap="handleSelect('follow', 0)"
						>
							我的关注
						</view>
						<view
							class="item round bg-gray"
							:class="{ action: currentItemId === 'home' }"
							@tap="handleSelect('home', 1)"
						>
							主页
						</view>
						<view
							class="item round bg-gray"
							v-for="(item, index) in common.modulesData.categoryModules"
							:key="item.id"
							:class="{ action: currentItemId === 'cid' + item.id }"
							@tap="handleSelect('cid' + item.id, index + 2)"
						>
							{{ item.name }}
						</view>
					</view>
				</view>
			</view>
			
			</view>
		</view>	
	</view>
	
</template>

<script>
import { mapState, mapActions } from 'vuex';

import wanlShopPage from '@/components/wanl-shop/page';
import wanlShopFind from '@/components/wanl-shop/find';
import wanlShopCategory from '@/components/wanl-shop/category';
export default {
	components: {
		
		wanlShopPage,
		wanlShopFind,
		wanlShopCategory
	},
	computed: {
		...mapState(['common', 'user', 'update','statistics'])
	},
	data() {
		return {
			headHeight: 0,
			windowHeight: 0,
			headTop: 1,
			currentItemId: 'home',
			currentData: {},
			scrollLeft: 0,
			isModal: false,
			contentText: {
				contentdown: '下拉加载更多',
				contentrefresh: '加载中',
				contentnomore: '我是有底线的'
			},
			search: false,
			hfwyData:[],
			show: true,
			showmsg:'399'
		};
	},
	onLoad(){
		// uni.getLocation({
		// 	type: 'wgs84',
		// 	geocode: true,
		// 	success: mres=> {
		// 		console.log(mres);
		// 	}
		// });
		this.loadData()		
	},
	onShow() {
		
		// #ifdef APP-PLUS
		plus.navigator.setFullscreen(false);
		// #endif
		// 计算页面尺寸
		let sys = this.$wanlshop.wanlsys();
		// #ifdef MP
		this.headHeight = sys.height;// + uni.upx2px(20)-20;
		// #endif
		// #ifdef APP-PLUS
		this.headHeight = sys.height + uni.upx2px(20)-20;
		// #endif
		this.windowHeight = sys.windowHeight;
		setTimeout(() => {
			uni.setNavigationBarColor({
				frontColor: this.$store.state.common.modulesData.homeModules.page
					? this.$store.state.common.modulesData.homeModules.page.style
							.navigationBarTextStyle
					: '',
				backgroundColor: this.$store.state.common.modulesData.homeModules.page
					? this.$store.state.common.modulesData.homeModules.page.style
							.navigationBarBackgroundColor
					: ''
			});
		}, 200);
		
		
	},
	onReady() {
		// 判断网络类型
		uni.getNetworkType({
			success: res => {
				if (res.networkType == '2g' || res.networkType == '3g' || res.networkType == '4g') {
					this.$wanlshop.msg('当前使用非WIFI环境，请注意流量使用');
				} else if (res.networkType == 'none') {
					this.$wanlshop.msg('没有网络');
				}
			}
		});
	},
	methods: {
		...mapActions({
			download: 'update/download', // 立即下载
			ignore: 'update/ignore' // 忽略更新
		}),
		loadData(){
			uni.request({
				url: '/wanlshop/ddp/gethfwy',
				data: {
					pageid: this.current_page,
					categoryid:8 					//话费文娱
				},
				success: res => {
					this.hfwyData = res.data.data; //评论数据 追加					
				}
			});	
					
		},
		concel(){
			this.show = false;
		},
		showMsg(){
			this.$wanlshop.msg('功能待上线，敬请期待！');
		},
		changeSearch(){
			this.search = true;
		},
		// 选择Tag
		handleSelect(id, index) {
			this.currentItemId = id;
			this.scrollLeft = (index - 1) * 50;
		},
		// 弹出层
		handleModal() {
			this.isModal = !this.isModal;
		},
		// 动画
		animationFinish(e) {
			//#ifdef APP-PLUS
			this.changeCurrent(e);
			//#endif
		},
		// 滚动的tag
		changeCurrent(e) {
			this.currentItemId = e.detail.currentItemId;
			this.scrollLeft = (e.detail.current - 1) * 50;
		},
		navto(p){
			this.$wanlshop.to('/pages/'+p)
		},
		// 一下扫码
		scanCode() {
			if(!this.$store.state.user.isLogin){
				this.$wanlshop.to('/pages/user/auth/auth');
				return
			}
			
			// #ifndef H5 
			uni.scanCode({
				success: res => {
					let QRcode = res.result;
					let sign = QRcode.substr(0,5);
					if(sign == 'DDGTH'){
						console.log(QRcode);
						let text = QRcode.substr(5);
						console.log(text);
						text = text.replace(/\%2B/g,'+');
						console.log(text);
						text = this.$wanlshop.decrypt(text);
						console.log(text);
						if(!this.user.partner){
							this.$wanlshop.msg('非经销商！');
							return;
						}
						this.$wanlshop.to('/pages/user2/partner/takeconfirm?text='+text);
					}else{
						let shopid = QRcode.substr(10);
						shopid = shopid.substr(0,shopid.length-10);
						let userid = this.$store.state.user.id;
						this.$wanlshop.to('/pages/user2/reimbursement/sitepay?shopid='+shopid+'&userid='+userid);
					}
					
					 
				}
			});
			// #endif
			// #ifdef H5
			this.$wanlshop.msg('暂不支持H5扫码');
			// #endif
		},
		// 解析Url
		getUrlParam(url) {
			var obj = {};
			var data = url.split('?')[1].split('&');
			for (var i = 0; i < data.length; i++) {
				var res = data[i].split('=');
				obj[res[0]] = res[1];
			}
			return obj;
		},
		// 搜索
		handleSearch(text) {
			this.$wanlshop.to(`/pages/page/search?type=goods&keywords=${text}`, 'fade-in', 100);
		},
		//禁止父元素滑动 1.0.3升级
		moveHandle() {}
		
	}
};
</script>

<style lang="scss">
.topioc{
	color: white;	
	position: absolute;
	right: 0;
	.text-xxl{
		font-size: 40rpx;
	}
}	
.image_logo{
			width: 180rpx;
			height: 70rpx;
		}
.wanlshop-container {
	&__head {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		z-index: 999;
	
		background-image: url('https://dundunpai.oss-cn-beijing.aliyuncs.com/OSS/20240801/a6bf8f9e9f8b25b3ab26eb1e690b50c6.png');
		background-repeat: no-repeat;
		background-size: 100% auto; 
		background-position: center center; 
		
		.navigater {
			height: 86rpx;
			padding-left: 25rpx;
			padding-right: 25rpx;
			/* #ifdef MP */
			padding-top: 140rpx;
			padding-right: 220rpx;
			/* #endif */
			.search {
				margin-left: 0;
				margin-right: 0;
				flex: 1;
				background-color: #fff;
				height: 66rpx;
				border: 2rpx solid #fff;
				.icon {
					margin: 0 20rpx;
				}
				swiper {
					height: 100%;
					width: 100%;
					margin-right: 10rpx;
					swiper-item {
						display: flex;
						align-items: center;
					}
				}
			}			
		}		
	}
	&__main {
		position: relative;
		z-index: 99;
	}
	.WANL-MODAL {
		.cu-modal {
			&.top-modal {
				background: rgba(0, 0, 0, 0.6);
				text-align: inherit;
				.cu-dialog {
					background: #fff;
					border-radius: 0 0 18rpx 18rpx;
					.category {
						display: grid;
						grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
						grid-auto-flow: row dense;
						grid-gap: 16rpx;
						.item {
							display: flex;
							align-items: center;
							justify-content: center;
							padding: 12rpx 0;
							border: 2rpx solid transparent;
							&.action {
								background-color: transparent;
								border-color: #f40;
								color: #f40;
								font-weight: bold;
							}
						}
					}
				}
			}
		}
	}
}
</style>
